package com.tiza.xiaoyoubao.ui.fragment;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.tianze.library.base.BaseFragment;
import com.tiza.xiaoyoubao.R;
import com.tiza.xiaoyoubao.app.UIHelper;
import com.tiza.xiaoyoubao.entity.RulesInfo;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by mapple on 17/3/6.
 */

public class UserRulesFragment extends BaseFragment {

    @BindView(R.id.tv_integralRules)
    TextView tv_integralRules;
    @BindView(R.id.lv_listView)
    ListView lv_listView;
    private List<RulesInfo> mList = new ArrayList();
    private MyAdapeter mMyAdapeter;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_user_rules;
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initView() {
        mList.add(new RulesInfo("10", "完成任务新手,订单编号:15", "2016-12-12 15:27:18"));
        mList.add(new RulesInfo("13", "完成任务,订单编号:15", "2016-12-12 15:27:18"));
        mList.add(new RulesInfo("15", "完成任务,订单编号:15", "2016-12-12 15:27:18"));
        mList.add(new RulesInfo("8", "完成任务,订单编号:15", "2016-12-12 15:27:18"));

        mMyAdapeter = new MyAdapeter();
        lv_listView.setAdapter(mMyAdapeter);
    }

    class MyAdapeter extends BaseAdapter {

        @Override
        public int getCount() {
            return mList.size();
        }

        @Override
        public Object getItem(int i) {
            return mList.get(i);
        }

        @Override
        public long getItemId(int i) {
            return i;
        }

        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {
            ViewHolder viewHolder;
            if (view == null) {
                view = View.inflate(getContext(), R.layout.fragment_rules_item, null);
                viewHolder = new ViewHolder();
                viewHolder.tvIntegral = (TextView) view.findViewById(R.id.tv_integral);
                viewHolder.tvLog = (TextView) view.findViewById(R.id.tv_log);
                viewHolder.tvTime = (TextView) view.findViewById(R.id.tv_time);
                view.setTag(viewHolder);
            } else {
                viewHolder = (ViewHolder) view.getTag();
            }
            viewHolder.tvIntegral.setText(mList.get(i).getTvIntegral());
            viewHolder.tvLog.setText(mList.get(i).getTvLog());
            viewHolder.tvTime.setText(mList.get(i).getTvTime());

            return view;
        }
    }

    static class ViewHolder {

        public TextView tvIntegral;
        public TextView tvLog;
        public TextView tvTime;
    }

    @OnClick({R.id.tv_integralRules})
    public void onClick(View view){
        switch (view.getId()){
            case R.id.tv_integralRules:
                UIHelper.showIntegralRules(mActivity);
                break;
        }
    }
}
